/*
 ============================================================================
 Name        : Tp0.c
 Author      : Santiago Storti
 Version     :
 Copyright   : Your copyright notice
 Description : Hello World in C, Ansi-style
 ============================================================================
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <getopt.h>
extern int imprimir(char *buffer,int);
extern void * realocar( void* ,size_t); 
extern void myfree(void *);
extern void desalocar(void*);

void cargar_stdin();
int procesarArchivo ( const char* nombre );

int main(int argc, char** argv)
{
	cargar_stdin();
	return 0;
}

void cargar_stdin() {
	long lSize = 20;
	void* bufferAux=NULL;
	void * buffer=NULL;
	int result;
	int tamanoAcumulado = 0;

	bufferAux =  realocar (NULL, sizeof(char)*(lSize));

	if (bufferAux==NULL) {
			printf ("NULL");
		return;
	}

	buffer =  realocar (NULL, sizeof(char)*(lSize));
	if (buffer==NULL){			printf ("NULL");
		free(bufferAux);
	}

	memset(bufferAux, 0, lSize);
	memset(buffer, 0, lSize);
//			printf ("\n.1.\n");
	result = fread(bufferAux, sizeof(char),lSize, stdin);
//			printf ("\n.2.\n");
	if (result>0) {
		memcpy(buffer,bufferAux,result);
		tamanoAcumulado += result;
	}
//			printf ("\n.3.\n");

	while( !feof(stdin) ) {
			//printf ("\n.4.\n");
		memset(bufferAux, 0, lSize);
		result = fread(bufferAux, sizeof(char), lSize, stdin);
			//printf ("da: ");
		buffer = realocar (buffer, sizeof(char)*(tamanoAcumulado+result));
		if (buffer == NULL) {
			free(bufferAux);
			printf ("sake");
		
		}
		void* aux = buffer+tamanoAcumulado;
		memcpy(aux,bufferAux,result);
		tamanoAcumulado +=  result;
	}
	//		printf ("ta");
	imprimir(buffer,tamanoAcumulado);
	desalocar (buffer);
	desalocar (bufferAux);

		

}
